package com.gt.quality.system.controller;


import com.gt.quality.base.BaseCommonController;
import com.gt.quality.base.BaseCommonService;
import com.gt.quality.system.entity.SysRoleMenu;
import com.gt.quality.system.entity.vo.RoleBindMenuVo;
import com.gt.quality.base.pojo.LayerListViewObject;
import com.gt.quality.base.pojo.Resp;
import com.gt.quality.system.service.SysRoleMenuService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 角色和菜单关联表(SysRoleMenu)表控制层
 *
 * @author makejava
 * @since 2026-11-25 16:30:08
 */
@RestController
@RequestMapping("sysRoleMenu")
@Tag(name = "角色关联菜单")
public class SysRoleMenuController extends BaseCommonController<SysRoleMenu> {
    /**
     * 服务对象
     */
    private SysRoleMenuService sysRoleMenuService;

    @Autowired
    public void setSysRoleMenuService(SysRoleMenuService sysRoleMenuService) {
        this.sysRoleMenuService = sysRoleMenuService;
    }

    @Override
    public BaseCommonService<SysRoleMenu> getThisService() {
        return sysRoleMenuService;
    }

    /**
     * 分配菜单
     */
    @PostMapping("/dispenseMenuTree")
    @Operation(summary = "分配菜单树")
    public Resp<LayerListViewObject> dispenseMenuTree(@RequestParam("id") Long id) {
        LayerListViewObject data = this.sysRoleMenuService.createTreeByLayer(id);
        Resp<LayerListViewObject> result = Resp.ok();
        result.setData(data);
        return result;
    }


    /**
     * 角色绑定菜单
     */
    @PostMapping("/roleBindMenu")
    @Operation(summary = "角色绑定菜单")
    public Resp<Boolean> roleBindMenu(@RequestBody RoleBindMenuVo body) {
        this.sysRoleMenuService.roleBindMenu(body);
        Resp<Boolean> result = Resp.ok();
        result.setData(Boolean.TRUE);
        return result;
    }

    @Override
    protected boolean isSuperExcel() {
        return false;
    }
}
